#ifndef MESSAGE_HANDLER
#define MESSAGE_HANDLER

#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>

#include "debug.h"

#include "utils.h"

static const int BUFFER_SIZE = 2048;

//@TODO : add a fonction to acces data allowing reallocation 
// of memory for long command

typedef enum {ANNOUNCE,LOOK,GETFILE,UPDATE,UNKNOWN} messageType;

typedef struct
{
  messageType type; 
  char* data;
} message;

int check_announce(message* m, char* buffer);
int check_look(message* m, char* buffer);
int check_getfile(message* m, char* buffer);
int check_update(message* m, char* buffer);

message* createMessage(int dataSize);
void freeMessage(message* m);


int getCommand(message* m, char* buffer);
int getCommandNumber(char* cmd);
char* getCommandString(int type);

char* waitForString(char* buffer, char* string);
int waitForInt(char* buffer);

#endif // MESSAGE_HANDLER

